#!/usr/bin/env python
# -*- coding: utf-8 -*-
#code:utf-8
#
# Copyright(C) 2011 SupDo.com
# Licensed under the GUN License, Version 3.0 (the "License");
# 
# File:        appModel.py
# Author:    KuKei
# Create Date: 2011-10-22
# Description: 应用部分模型
# Modify Date: 2011-10-22

from django.db import models
from sd.cms.lib import SDFileSystemStorage
from sd.cms.models import BaseModel
from sd.cms.models.paramModel import *
from sd.cms.models.userModel import *
from sd import settings

STATUS_CHOICES = (
    (0, '草稿.'),
    (1, '发布.'),
    (2, '加密.'),
    (3, '隐藏.'),
)
    
class ArticleContent(BaseModel):
    content = models.TextField("内容")

class Article(BaseModel):
    title = models.CharField("标题", max_length=50)
    content = models.ForeignKey(ArticleContent, verbose_name="内容")
    summary = models.TextField("摘要", null=True)
    catalog = models.ForeignKey(Catalog, verbose_name='目录', limit_choices_to = {'kind':1, 'islast': True, 'isdisplay': True})
    type = models.IntegerField('类型', null=True)
    tag = models.IntegerField('标签', null=True)
    name = models.CharField("地址名", max_length=50, null=True, blank=True, db_index=True, help_text="url地址名")
    status = models.IntegerField('状态', choices=STATUS_CHOICES, default=1)
    frontcover = models.CharField("封面", max_length=100, blank=True)
    crtdate = models.DateTimeField('生成时间')
    moddate = models.DateTimeField('修改时间', null=True)
    author = models.IntegerField('作者')
    readcnt = models.IntegerField('浏览数', default=0)
    commentcnt = models.IntegerField('回复数', default=0)
    isComment = models.BooleanField("允许评论", blank=True, default=True)
    
    class Meta(BaseModel.Meta):
        ordering = ["id"]

class ArticleCmt(BaseModel):
    article = models.ForeignKey(Article)
    pid = models.IntegerField('上级', db_index=True, default=-1)
    author = models.CharField("作者", max_length=50)
    email = models.EmailField("邮箱", max_length=50)
    homepage = models.URLField("网站", max_length=50, null=True, blank=True)
    date = models.DateTimeField('发布时间')
    content = models.TextField("评论内容")
    
#图片库模型
class Image(BaseModel):
    KIND_CHOICES = (
        (1, '首页展播'),
    )
    kind = models.IntegerField("类型", choices=KIND_CHOICES)
    name = models.CharField("名称", max_length=50)
    linkUrl = models.CharField("链接地址", max_length=50)
    thumbnail = models.CharField("缩略图", max_length=120, null=True, blank=True)
    image = models.CharField("图片", max_length=120)
    describe = models.TextField("描述", null=True)
    orderby = models.IntegerField("显示顺序")
    isdisplay = models.BooleanField("是否显示", default=True)
    

#产品模型
class Product(BaseModel):
    title = models.CharField("名称", max_length=50)
    content = models.TextField("简介")
    catalog = models.ForeignKey(Catalog, verbose_name='目录', limit_choices_to = {'kind':1, 'islast': True, 'isdisplay': True})
    name = models.CharField("地址名", max_length=50, null=True, blank=True, db_index=True, help_text="url地址名")
    status = models.IntegerField('状态', choices=STATUS_CHOICES, default=1)
    frontcover = models.CharField("封面", max_length=100, blank=True)
    crtdate = models.DateTimeField('生成时间')
    moddate = models.DateTimeField('修改时间', null=True)
    author = models.IntegerField('作者')
    readcnt = models.IntegerField('浏览数', default=0)
    commentcnt = models.IntegerField('回复数', default=0)
    isComment = models.BooleanField("是否允许评论", blank=True)
    isShow = models.BooleanField("是否展示", blank=False)
    
class ProductParam(BaseModel):
    product = models.ForeignKey(Product, verbose_name="所属产品")
    title = models.CharField("标题", max_length=50)
    value = models.CharField("内容", max_length=50)
    value1 = models.TextField("内容2", null=True)
    orderby = models.IntegerField("显示顺序")
    isdisplay = models.BooleanField("是否显示", default=True)
    isimportant = models.BooleanField("重要")
    
class ProductCmt(BaseModel):
    article = models.ForeignKey(Product)
    pid = models.IntegerField('上级', db_index=True, default=-1)
    author = models.CharField("作者", max_length=50)
    email = models.EmailField("邮箱", max_length=50)
    homepage = models.URLField("网站", max_length=50, null=True, blank=True)
    date = models.DateTimeField('发布时间')
    content = models.TextField("评论内容")
    
class GuestBook(BaseModel):
    title = models.CharField("标题", max_length=50)
    message = models.TextField("内容")
    author = models.ForeignKey(User, verbose_name='作者', null=True, blank=True)
    authorname = models.CharField("作者名称", max_length=50)
    email = models.EmailField("邮箱", max_length=50)
    crtdate = models.DateTimeField('发布时间', auto_now_add=True)
    ip = models.CharField("IP", max_length=50)
    isdisplay = models.BooleanField("是否显示", default=True)
    reply = models.TextField("回复", default='', null=True, blank=True)
    replydate = models.DateTimeField('回复时间', auto_now=True, null=True, blank=True)